package sketch.ui;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.util.HashMap;

public class DrawOption {

	private DrawOption() {}

	private static HashMap<String, Color> colors = null;

	private static HashMap<String, Stroke> strokes = null;

	public static void restoreDrawColor(Graphics2D g2) {
		g2.setColor(prevColor);
	}

	public static void restoreDrawStroke(Graphics2D g2) {
		g2.setStroke(prevStroke);
	}

	private static Color prevColor;

	private static Stroke prevStroke;

	public static void saveDrawColor(Graphics2D g2) {
		prevColor = g2.getColor();
	}

	public static void saveDrawStroke(Graphics2D g2) {
		prevStroke = g2.getStroke();
	}

	public static void restoreDrawOptions(Graphics2D g2) {
		restoreDrawColor(g2);
		restoreDrawStroke(g2);
	}

	public static void saveDrawOptions(Graphics2D g2) {
		saveDrawColor(g2);
		saveDrawStroke(g2);
	}

	public static Color getColor(String type) {
		if (colors == null) {
			colors = new HashMap<String, Color>();

			colors.put("Line", Color.BLUE);
		}

		Color color = colors.get(type);
		if (color == null)
			color = Color.BLACK;

		return color;
	}

	public static Stroke getStroke(String type) {
		if (strokes  == null) {
			strokes = new HashMap<String, Stroke>();

			strokes.put("Line", new BasicStroke(2));
		}

		Stroke stroke = strokes.get(type);
		if (stroke == null)
			stroke = new BasicStroke(1);

		return stroke;
	}

}
